import { Radio, RadioChangeEvent } from "antd";
import { useState } from "react";
import ViewUserAuth from "./components/ViewUserAuth";
import ViewMenuAuth from "./components/ViewMenuAuth";
import {  useSearchParams } from "react-router-dom";

export default function Permission() {
  const [activeKey, setActiveKey] = useState("0");
  const [searchParams] = useSearchParams();
  const roleId = searchParams.get('roleId')||'';
  const roleName = searchParams.get('roleName')||'';
  console.log(roleId,roleName);
  
  return (
    <div className="page__wrap--g">
      <div className="form__wrap--g">
        <Radio.Group
          size="middle"
          options={[
            { label: "分配菜单", value: "0" },
            { label: "分配用户", value: "1" },
          ]}
          onChange={({ target: { value } }: RadioChangeEvent) => {
            setActiveKey(value);
          }}
          value={activeKey}
          optionType="button"
          buttonStyle="solid"
        />
      </div>
      <div className="table__wrap--g no-page">
        {
          {
            0: <ViewMenuAuth roleId={roleId} roleName={roleName} />,
            1: <ViewUserAuth roleId={roleId} roleName={roleName} />,
          }[activeKey]
        }
      </div>
    </div>
  );
}
